package com.qut.graduate.busrtquery.utils.common;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

public class ApkVersionUtils {

    /*
     * 获取当前程序的版本名
     */
    public static String getVersionName(){
        String versionName = "1.0.1";
        try {
            // 获取packagemanager的实例
            PackageManager packageManager = ContextUtils.getContext().getPackageManager();
            // getPackageName()是当前类的包名，0代表是获取版本信息
            PackageInfo packInfo = packageManager.getPackageInfo(ContextUtils.getContext().getPackageName(), 0);
            versionName =  packInfo.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            LogUtils.d("E-获取版本名异常：" + e);
        }
        return versionName;
    }

    /*
     * 获取当前程序的版本号
     */
    public static int getVersionCode(){
        int versionCode = 1;
        try {
            // 获取packagemanager的实例
            PackageManager packageManager = ContextUtils.getContext().getPackageManager();
            // getPackageName()是你当前类的包名，0代表是获取版本信息
            PackageInfo packInfo  = packageManager.getPackageInfo(ContextUtils.getContext().getPackageName(), 0);
            versionCode = packInfo.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            LogUtils.d("E-获取版本号异常：" + e);
        }
        return versionCode;
    }

}
